package com.sthz.facepay.mapper;

import com.sthz.facepay.model.Classification;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;

public interface ClassificationMapper {
    @Delete({
        "delete from st_classification",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into st_classification (id, name, ",
        "peid, coid, opid)",
        "values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
        "#{peid,jdbcType=INTEGER}, #{coid,jdbcType=INTEGER}, #{opid,jdbcType=INTEGER})"
    })
    int insert(Classification record);

    @InsertProvider(type=ClassificationSqlProvider.class, method="insertSelective")
    int insertSelective(Classification record);

    @Select({
        "select",
        "id, name, peid, coid, opid",
        "from st_classification",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="peid", property="personal", one=@One(select="com.sthz.facepay.mapper.PersonalMapper.getById",fetchType = FetchType.EAGER)),
        @Result(column="coid", property="cost", one=@One(select="com.sthz.facepay.mapper.CostMapper.getById",fetchType = FetchType.EAGER)),
        @Result(column="opid", property="operate", one=@One(select="com.sthz.facepay.mapper.OperateMapper.getById",fetchType = FetchType.EAGER))
    })
    Classification selectByPrimaryKey(Integer id);

    @UpdateProvider(type=ClassificationSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Classification record);

    @Update({
        "update st_classification",
        "set name = #{name,jdbcType=VARCHAR},",
          "peid = #{peid,jdbcType=INTEGER},",
          "coid = #{coid,jdbcType=INTEGER},",
          "opid = #{opid,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Classification record);
}